package com.zimmor.routing;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zimmor.util.RabbitmqUtil;

import java.io.IOException;

/**
 * @Author:zimmor
 * @Date: 2021/12/29 15:58
 * @Description 路由模型 生产者
 * @version: 1.0.0
 */

public class Provider {
    public static void main(String[] args) {
        //获取连接和通道
        Connection connection = RabbitmqUtil.getConnection();
        try {
            Channel channel = connection.createChannel();
            //声明交换机 type direct
            String exchange = "routing";
            channel.exchangeDeclare(exchange, BuiltinExchangeType.DIRECT);
            //定义路由routingKey
            String routingKey = "user.add";
            //发送消息
            channel.basicPublish(exchange, routingKey, null, "路由模式发送的消息".getBytes());
            //关闭连接和通道
            RabbitmqUtil.close(channel, connection);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
